﻿@using Seal.Model
@using Seal.Helpers
@{
    Report report = Model;
    ReportView view = report.CurrentView;
    Repository repository = report.Repository;
}

<!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel='shortcut icon' href='@report.AttachImageFile("favicon.ico")' type='image/x-icon' />
    <title>
        @report.ExecutionName
    </title>

    <!--CSS-->
    @Raw(report.AttachCSSFile("bootstrap.min.css", report.GenerateHTMLDisplay && report.ExecutionContext == ReportExecutionContext.DesignerReport ? "" : "https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css"))
    @Raw(report.AttachCSSFile("bootstrap-select.min.css", "https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.12.4/css/bootstrap-select.min.css"))
    @Raw(report.AttachCSSFile("bootstrap-datetimepicker.min.css"))
    <!-- CSS DataTables-->
    @Raw(report.AttachCSSFile("dataTables.bootstrap.min.css", "https://cdn.datatables.net/1.10.19/css/dataTables.bootstrap.min.css"))
    @Raw(report.AttachCSSFile("responsive.bootstrap.min.css", "https://cdn.datatables.net/responsive/2.2.2/css/responsive.bootstrap.min.css"))

    @Raw(report.AttachCSSFiles(repository.Configuration.CssFiles))
    @Raw(report.AttachCSSFile("seal.css"))

    <!--Scripts-->
    @Raw(report.AttachScriptFile("jquery.min.js", "https://code.jquery.com/jquery-1.12.4.min.js"))
    @Raw(report.AttachScriptFile("bootstrap.min.js", "https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"))
    @Raw(report.AttachScriptFile("bootstrap-select.min.js", "https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.12.4/js/bootstrap-select.min.js"))
    @Raw(report.AttachScriptFile("moment.min.js"))
    @if (view.CultureInfo.TwoLetterISOLanguageName != "en")
    {
        @Raw(report.AttachScriptFile("i18n\\moment." + view.CultureInfo.TwoLetterISOLanguageName + ".js"))
        @Raw(report.AttachScriptFile("i18n\\selectpicker." + view.CultureInfo.TwoLetterISOLanguageName + ".min.js"))
    }
    @Raw(report.AttachScriptFile("bootstrap-datetimepicker.min.js"))

    <!--Scripts Datatables-->
    @Raw(report.AttachScriptFile("jquery.dataTables.min.js", "https://cdn.datatables.net/1.10.18/js/jquery.dataTables.min.js"))
    @Raw(report.AttachScriptFile("dataTables.bootstrap.min.js", "https://cdn.datatables.net/1.10.18/js/dataTables.bootstrap.min.js"))
    @Raw(report.AttachScriptFile("dataTables.responsive.min.js"))
    @Raw(report.AttachScriptFile("responsive.bootstrap.min.js", "https://cdn.datatables.net/responsive/2.2.2/js/responsive.bootstrap.min.js"))

    @Raw(report.AttachScriptFile("datetime-moment.js"))
    @if (report.HasChart)
    {
        @Raw(report.AttachScriptFile("d3.min.js"))
        @Raw(report.AttachScriptFile("d3-time.v1.min.js", "https://d3js.org/d3-time.v1.min.js"))
        @Raw(report.AttachScriptFile("d3-time-format.v2.min.js", "https://d3js.org/d3-time-format.v2.min.js"))
        @Raw(report.AttachScriptFile("d3\\" + view.CultureInfo.TwoLetterISOLanguageName + ".js"))
    }

    @if (report.HasChartJSChart)
    {
        @Raw(report.AttachScriptFile("Chart.min.js", "https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.8.0/Chart.min.js"))
    }

    @if (report.HasPlotlyChart)
    {
        @Raw(report.AttachScriptFile("plotly-latest.min.js", "https://cdn.plot.ly/plotly-1.48.1.min.js"))
        @Raw(report.AttachScriptFile("plotly\\plotly-locale-" + view.CultureInfo.TwoLetterISOLanguageName + ".js"))
    }

    @if (report.HasNVD3Chart)
    {
        @Raw(report.AttachScriptFile("nv.d3.min.js"))
        @Raw(report.AttachCSSFile("nv.d3.min.css"))
        <script>
                function nvd3TranslateText(text)
                {
                    @foreach (var translation in repository.NVD3Translations)
                    {
                    <text>if (text == '@Raw(Helper.ToJS(translation.Key))') return '@Raw(Helper.ToJS(translation.Value))';</text>
                    }
                    return text;
                }
        </script>
        @Raw(report.AttachScriptFile("chartNVD3.js"))
    }
    @Raw(report.AttachScriptFiles(repository.Configuration.ScriptFiles))

    <script type="text/javascript">
            var generateHTMLDisplay =  @Helper.ToJS(report.GenerateHTMLDisplay);

            var urlPrefix = "@report.WebUrl";
            var executionTimer = null;
            var refreshTimer = null;
            var refreshRate = @view.GetNumericValue("refresh_rate");
            var hasRestrictions = @Helper.ToJS(report.HasRestrictions);
            var showRestrictions = @Helper.ToJS(report.HasRestrictions && view.GetBoolValue("restriction_button"));
            var hasNavigation = @Helper.ToJS(report.HasNavigation && (report.IsNavigating || report.GenerateHTMLDisplay));/*SRKW do not modify*/
            var forceExecution = @Helper.ToJS(view.GetBoolValue("force_execution") || report.HasNavigation);
            var isExecuting = @Helper.ToJS(report.IsExecuting);
            var isCancel = @Helper.ToJS(report.Cancel);
            var printLayout = @Helper.ToJS(report.PrintLayout);
            var autoscroll = false;

            var rootViewId = '@view.ViewId';

            //text
            var messagesText = '@report.Translate("Messages")';
            var startingExecText = '@report.Translate("Starting execution...")';
            var cancelText = '@report.Translate("Cancel")';

            //formats
            var languageName = '@view.CultureInfo.TwoLetterISOLanguageName';
            var decimalSeparator = '@Raw(view.CultureInfo.NumberFormat.NumberDecimalSeparator)';
            var shortDateFormat = '@Raw(repository.MomentJSShortDateFormat)';
            var shortDateTimeFormat = '@Raw(repository.MomentJSShortDateTimeFormat)';
            var thousandSeparator = '@Raw(Helper.ToJS(view.CultureInfo.NumberFormat.NumberGroupSeparator))';
            var currencySymbol = '@Raw(Helper.ToJS(view.CultureInfo.NumberFormat.CurrencySymbol))';

            var dtTooltips = {
                today: '@Raw(report.TranslateToJS("Go to today")))',
                clear: '@Raw(report.TranslateToJS("Clear selection"))',
                close: '@Raw(report.TranslateToJS("Close"))',
                selectMonth: '@Raw(report.TranslateToJS("Select Month"))',
                prevMonth: '@Raw(report.TranslateToJS("Previous Month"))',
                nextMonth: '@Raw(report.TranslateToJS("Next Month"))',
                selectYear: '@Raw(report.TranslateToJS("Select Year"))',
                prevYear: '@Raw(report.TranslateToJS("Previous Year"))',
                nextYear: '@Raw(report.TranslateToJS("Next Year"))',
                selectDecade: '@Raw(report.TranslateToJS("Select Decade"))',
                prevDecade: '@Raw(report.TranslateToJS("Previous Decade"))',
                nextDecade: '@Raw(report.TranslateToJS("Next Decade"))',
                prevCentury: '@Raw(report.TranslateToJS("Previous Century"))',
                nextCentury: '@Raw(report.TranslateToJS("Next Century"))',
                pickHour: '@Raw(report.TranslateToJS("Pick Hour"))',
                incrementHour: '@Raw(report.TranslateToJS("Increment"))',
                decrementHour: '@Raw(report.TranslateToJS("Decrement"))',
                pickMinute: '@Raw(report.TranslateToJS("Pick Minute"))',
                incrementMinute: '@Raw(report.TranslateToJS("Increment"))',
                decrementMinute: '@Raw(report.TranslateToJS("Decrement"))',
                pickSecond: '@Raw(report.TranslateToJS("Pick Second"))',
                incrementSecond: '@Raw(report.TranslateToJS("Increment"))',
                decrementSecond: '@Raw(report.TranslateToJS("Decrement"))',
                togglePeriod: '@Raw(report.TranslateToJS("Toggle Period"))',
                selectTime: '@Raw(report.TranslateToJS("Select Time"))'
            }
            $.fn.dataTable.moment(shortDateFormat);
            $.fn.dataTable.moment(shortDateTimeFormat);
            $.extend( true, $.fn.dataTable.defaults, {
                responsive: {
                    details: {
                        renderer: function (api, rowIdx, columns) {
                            var data = $.map(columns, function (col, i) {
                                var cellDatas = col.data.split('§', 6);
                                return col.hidden ?
                                    '<tr data-dt-row="' + col.rowIndex + '" data-dt-column="' + col.columnIndex + '">' +
                                    '<th>' + col.title + (col.title != '' ? ':' : '') + '</th> ' +
                                    (cellDatas.length == 1 ? '<td>' + col.data : '<td style="' + cellDatas[3] + '" class="' + cellDatas[4] + '">' + cellDatas[5]) + '</td>' +
                                    '</tr>' :
                                    '';
                            }).join('');

                            return data ?
                                $('<table/>').append(data) :
                                false;
                        }
                    }
                },
                columnDefs: [
                    { orderable: false, targets: ["firstcell"]}
                    @if (report.IsServerPaginationEnabled)
                    {
                        <text>,
                        {
                            targets: "_all",
                            createdCell: function(td, cellData, rowData, row, col) {
                                var cellDatas = cellData.split('§', 6);
                                $(td).html(cellDatas[5]);
                                $(td).attr("class", cellDatas[4]);
                                $(td).attr("style", cellDatas[3]);
                                $(td).attr("navigation", cellDatas[2]);
                                $(td).parent().attr("class", cellDatas[1]);
                                $(td).parent().attr("style", cellDatas[0]);
                            }
                        }
                        </text>
                    }
                ],
                language: {
                    decimal: decimalSeparator,
                    thousands: thousandSeparator,
                    processing: "@report.Translate("Processing...")",
                    lengthMenu: "@report.Translate("Show _MENU_ rows")",
                    zeroRecords: "@report.Translate("No rows")",
                    emptyTable: "@report.Translate("No records")",
                    info: "@report.Translate("Showing _START_ to _END_ of _TOTAL_")",
                    infoEmpty: "@report.Translate("Showing 0 to 0 of 0")",
                    infoFiltered: "@report.Translate("(filtered from _MAX_)")",
                    infoPostFix: "",
                    search: "@report.Translate("Filter:")",
                    paginate: {
                        first: "|&lt;",
                        previous: "&lt;&lt;",
                        next: ">>",
                        last: ">|"
                    }
                },
                pagingType: "full_numbers",
                autoWidth: false,
                stateSave: @Helper.ToJS(!string.IsNullOrEmpty(report.WebUrl)),
                stateSaveCallback: function(settings,data) {
                    try {
                        (settings.iStateDuration === -1 ? sessionStorage : localStorage).setItem(
                            'DataTables_'+settings.sInstance+'_Result',
                            JSON.stringify( data ));
                    } catch (e) {}
                },
                stateLoadCallback: function(settings) {
                    try {
                        return JSON.parse(
                            (settings.iStateDuration === -1 ? sessionStorage : localStorage).getItem(
                                'DataTables_'+settings.sInstance+'_Result'
                            ));
                    } catch (e) {}
                }
        });
    </script>
    @Raw(report.AttachScriptFile("helpers.js"))
    @Raw(report.AttachScriptFile("common.js"))
    @Raw(report.AttachScriptFile("custom.js"))
    <script>
            @Raw(view.GetValue("additional_js"))
    </script>
    <style>
            @Raw(view.GetValue("additional_css"))
    </style>
</head>
<body>
    @Include(view.GetPartialTemplateKey("Report.iHeader", view), view)

    <div id="main_container" class="container@(view.GetBoolValue("container_fluid") ? "-fluid" : "")" style="display:none;">
        <form id="header_form" method="post" action="">
            <input type="hidden" name="execution_guid" id="execution_guid" value="@report.ExecutionGUID" />
            <input type="hidden" name="navigation_id" id="navigation_id" value="" />
            <input type="hidden" name="viewid_tableload" id="viewid_tableload" value="" />
            <input type="hidden" name="pageid_tableload" id="pageid_tableload" value="" />
            <input type="hidden" name="id_enumload" id="id_enumload" value="" />
            <input type="hidden" name="values_enumload" id="values_enumload" value="" />
            <input type="hidden" name="filter_enumload" id="filter_enumload" value="" />

            <input type="hidden" name="parameter_view_id" id="parameter_view_id" value="" />
            <input type="hidden" name="parameter_view_name" id="parameter_view_name" value="" />
            <input type="hidden" name="parameter_view_value" id="parameter_view_value" value="" />

            <span style="display: none;" id="parameter_tableload"></span>
            <span style="display: none;" id="parameter_enumload"></span>
            @Include(view.GetPartialTemplateKey("Report.iRestrictions", view), view)
        </form>

        <!-- status-->
        <div id="alert_status">
            @if (report.Cancel)
            {
                <div class="alert alert-danger" role="alert">
                    @Raw(Helper.ToHtml(report.Translate("Report has been cancelled")))
                </div>
            }
            @if (!string.IsNullOrEmpty(report.WebExecutionErrors))
            {
                <div class="alert alert-danger" role="alert">
                    @Raw(Helper.ToHtml(report.WebExecutionErrors))
                </div>
            }
        </div>

        <!--progress-->
        <div id="progress_panel" class="panel panel-default hidden">
            <div class="panel-body" style="padding-bottom:0px;">
                <div class="progress hidden">
                    <div id="progress_bar" class="progress-bar progress-bar-success progress-bar-striped active" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width:0%;">
                    </div>
                </div>
                @if (report.ExecutionTasks.Count > 0)
                {
                    <div class="progress hidden">
                        <div id="progress_bar_tasks" class="progress-bar progress-bar-primary progress-bar-striped active" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width:0%;">
                        </div>
                    </div>
                }
                @if (report.ExecutionModels.Count > 0)
                {
                    <div class="progress hidden">
                        <div id="progress_bar_models" class="progress-bar progress-bar-info progress-bar-striped active" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width:0%;">
                        </div>
                    </div>
                }
            </div>
        </div>

        <div class="tab-content">
            @Include(view.GetPartialTemplateKey("Report.iInformation", view), view)
            @Include(view.GetPartialTemplateKey("Report.iMessages", view), view)
            @Include(view.GetPartialTemplateKey("Report.iViews", view), view)
        </div>
    </div>

    <!--back to top-->
    <a id="back-to-top" href="#" class="btn btn-warning btn-lg back-to-top" role="button" title="@report.Translate("Back to top")" data-toggle="tooltip" data-placement="top">
        <span>&#916;</span>
        <span id="back-to-top-close" style="top:0px;right:4px;font-size:14px;position:absolute;">&times;</span>
    </a>
</body>
</html>
